
$(document).ready(function() {
	
	var remainTxCount = 3;
	
	AQ.callAQ("getDayTxCount.do", null, function(result) {
		$("#ava-money").text(result[1].avaTxMoney);
		$("#tx-count").text(result[1].remainTxCount);
	}, function(err, code) {
		console.log(err + "["+ code +"]");
	});
	
	var zhifubao = "";
	try {
		zhifubao = $.parseJSON($.cookie('User')).zhifubao;
	} catch(e) {
		console.log(e);
	}
    if(zhifubao.length == 0) {
		Utils.checkDialog("您还未绑定提现支付宝，请先绑定提现支付宝！", "绑定支付宝", "返回", function() {
			location.replace("bind-pay.html");
		}, function() {
			location.replace("user-center.html");
		});
	}
	
	/* 提交支付宝交易号 */
	$(".yz-pay-no-bt").click(function(e) {
		if(remainTxCount <= 0) {
			Utils.msgDialog("今日提现次数已达上限，请明日再进行提现！");
			return;
		}
		var money = 0;
		var identityLevel = 0;
		try {
			var User = $.parseJSON($.cookie('User'));
			money = parseInt(User.money);
			vip = parseInt(User.vip);
		} catch(e) {
			console.log(e);
		}
		var txMoney = $(".yz-pay-no").val();
		var moneyReg = /^[1-9][0-9]{0,5}$/;
		if(!moneyReg.test(txMoney)) {
			Utils.msgDialog("提现金额必须为整数（如：321）");
			return;
		} else if(txMoney >= 10) {
			if(txMoney > money) {
				Utils.msgDialog("提现金额不能大于" +money+ "元！");
				return;
			}
		} else if(txMoney < 10 && vip == 0) {
			if(txMoney > money-2) {
				Utils.msgDialog("提现金额不能大于" +(money-2)+ "元！");
				return;
			}
		}
		
		var param = {
			money: txMoney,
		};
        AQ.callAQ("applyTx.do", param, function(result) {
			Utils.msgDialog("提交成功");
			$("#tx-count").text(--remainTxCount);
			Utils.refreshUserInfo();	//刷新用户信息
			$(".yz-pay-no").val("");
		}, function(err, code) {
			Utils.msgDialog(err + "["+ code +"]");
		});
    });
	
});